package com.ayz.apigatewaytestdemo.service;


import com.ayz.apigatewaytestdemo.pojo.User;
import com.ayz.gateway.springbootstarter.annotation.ApiProviderClazz;
import com.ayz.gateway.springbootstarter.annotation.ApiProviderMethod;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.HashMap;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author 快乐的星球
 * @Date 2023/5/7 15:30
 * @Version 1.0
 **/
@DubboService
@ApiProviderClazz
public class UserServiceImpl implements IUserService{

    private static final HashMap<String, User> map=new HashMap<>();
    static {
        map.put("1",new User("1","张三",20));
        map.put("2",new User("2","李四",31));
        map.put("3",new User("3","王五",24));
    }

    @ApiProviderMethod(httpUri = "testDemo")
    @Override
    public User getUserById(String id) {
        User user = map.get(id);
        if(user==null){
            throw new IllegalArgumentException("当前Id没有注册!");
        }
        return user;
    }

    @ApiProviderMethod(httpUri = "testDemo2")
    @Override
    public void addUser(User user) {
        System.out.println(" 添加用户 :"+user.toString());
        map.put(user.getId(),user);
    }
}
